package com.mdb;

import java.io.Serializable;

import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import com.dao.UsuarioDAO;

/**
 * Session Bean implementation class MensagemBean
 */
@SuppressWarnings("serial")
@Stateless(mappedName = "MensagemBeanRemote")
public class MensagemBean implements MensagemBeanRemote, Serializable {

	@EJB
	private UsuarioDAO usuarioDao;
	//private Usuario usuario = new Usuario();

	@Resource(mappedName = "jms/fabricaFilaProjeto3POD")
	private ConnectionFactory cf;

	@Resource(mappedName = "jms/filaProjeto3POD")
	private Queue queue;

	@Override
	public void enviaMensagem(String mensagem) throws JMSException {
		//public void enviaMensagem() throws JMSException{
		Connection con = cf.createConnection();

		Session session = con.createSession(true, 0);

		MessageProducer mp = session.createProducer(queue);

		TextMessage msg = session.createTextMessage();

		msg.setStringProperty("mensagem", mensagem);

		mp.send(msg);

		mp.close();
		session.close();
		con.close();
	}
}
